package com.itheima.package1_threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/*
Thread.State:线程状态
new                     新建--创建线程对象
runnable                就绪--调用strt方法
blocked                 阻塞--获取不到锁
waitting                等待--调用了wait方法
timewatting             等待--sleep方法或者带参数的wait方法
terminated              死亡--线程结束

*/
public class Demo1_ThreadPool {
    public static void main(String[] args) throws InterruptedException {
        //通过Executors获取默认的线程池,返回一个ExecutorService对象
        ExecutorService pool = Executors.newCachedThreadPool();
        //ExecutorService对象提交任务
        pool.submit(()-> System.out.println(Thread.currentThread().getName()+"开始了"));
        Thread.sleep(100);//让线程有足够的时间返还
        //创建线程并将使用完的线程归还池子,自动完成
        pool.submit(()-> System.out.println(Thread.currentThread().getName()+"结束了"));
//        pool.shutdown();手动调用方法停止池子,默认存活一分钟
    }
}
